<?php
namespace app\common\model;
use app\common\model\Base;
class Loan extends Base
{
    protected $insert = ['create_time'];
    protected $update = ['update_time'];
	protected function _filter($data){
		if($data['keywords']!=""){
			$data['realname'] = array('like','%'.$data['keywords'].'%');
		}
        unset($data['keywords']);
        if($data['txrq']!=""){
            $data['extra'] = ['like','%"txrq":"'.$data['txrq'].'"%'];
        }
        unset($data['txrq']);
        if($data['date']){
            $stime =0;
            $etime =0;
            if(strpos('至',$data['date'])){
                $date = explode('至', $data['date']);
                $stime = strtotime($date[0]);
                $etime = strtotime($date[1]);
            }else{
                $stime = strtotime($data['date'].'-01');
                $date = new \DateTime(date('Y-m-d',$stime));
                $etime = $date->add(new \DateInterval('P1M'))->getTimestamp();
            }
            $data['date']=['between',[date('Y-m-d',$stime),date('Y-m-d',$etime)]];
        }
		return $data;
	} 
    protected function setCreateTimeAttr()
    {
        return time();
    }
    protected function setUpdateTimeAttr()
    {
        return time();
    }

    public function getExtraAttr($value,$data){
        $extra = json_decode($value,true);
        return $extra;
    }
    public function setExtraAttr($value,$data){
        return json_encode($value);
    }

    public function getGpsAttr($value,$data){
        return json_decode($value,true);
    }
    public function setGpsAttr($value,$data){
    	$value = $value ? $value : [];
        return json_encode($value);
    }

    /*public function getAttachsAttr($value,$data){
        return json_decode($value,true);
    }*/
    /*public function setAttachsAttr($value,$data){
        return json_encode($value);
    }*/

    public function getSalesmanAttr($value,$data){
        return Salesman::get($value);
    }

    public function getFinalMoneyAttr($value,$data){
        return $value ? $value : '待核';
    }
    public function setFinalMoneyAttr($value,$data){
        return $value ? ($value=='待核' ? 0 : $value): 0;
    }
}
